<?php
/**
 * Created by IntelliJ IDEA.
 * User: skyADMIN
 * Date: 15/9/14
 * Time: 上午9:11
 */
session_start();
require_once ('connect.php');

$action = $_GET['action'];
if($action == 'login'){
    $user = stripslashes(trim($_POST['user']));
    $pass = stripslashes(trim($_POST['pass']));
    if (empty ($user)) {
        echo '用户名不能为空';
        exit;
    }
    if (empty ($pass)) {
        echo '密码不能为空';
        exit;
    }
    $md5pass = md5($pass);
    $query = mysql_query("select uid from login where username='$user' and password='$md5pass' limit 1");
    if($result = mysql_fetch_array($query)){
        $_SESSION['uid'] = $result['uid'];
        $_SESSION['user'] = $user;
        echo 1;
    }else{
        echo 0;
    }
}else if($action == 'exit'){
    session_destroy();
    echo -1;
}
?>